package dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;



import vo.Address;
import vo.Client;
import vo.OrderForm;
import dao.ClientDao;
@Repository("cd")
public class ClientDaoImpl implements ClientDao {
	@PersistenceContext(name="un")
	private EntityManager em;
	@Override
	public int addClient(Client client) {
		int rs = 0;
		em.persist(client);
		return client.getId();
	}
	
	
/*	String jpql="select l from log l";
	List<Log> ls=em.createQuery(jpql).getResultList();
	if(ls.isEmpty()) return null;
	else return ls;*/

	@SuppressWarnings("unchecked")
	@Override
	public Client findClient(String username, String passwd) {
		String jpql = "select c from Client c where c.username=:username and c.passwd=:passwd";
		List<Client> cls = em.createQuery(jpql)
				.setParameter("username", username)
				.setParameter("passwd", passwd).getResultList();

		if (cls.isEmpty()) {
			return null;
		}else{
			return cls.get(0);
		}
	}

	@Override
	public Boolean findTel(String tel) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int addAddress(Address address) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public int addOrderForm(OrderForm orderForm) {
		// TODO Auto-generated method stub
		return 0;
	}

}
